<html>
<head>
<title>MonadSphere</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">

<script type="text/javascript" src="json2.js"></script>
<script type="text/javascript">

  monadsphere = {};
  monadsphere.ids = {};
  
  monadsphere.remoteCall = function (callName, data) {
    var path = window.location.pathname;
    callName = path.substring(0, path.lastIndexOf('/') + 1) + callName;
    var httpRequest = new XMLHttpRequest();
    httpRequest.onreadystatechange = function() {
      monadsphere.processResponse(httpRequest);
    };
    if (typeof(data) == 'undefined' || data == null) {
      httpRequest.open('GET', callName, true);
      httpRequest.send(null);
    } else {
      httpRequest.open('POST', callName, true);
      
      alert(JSON.stringify(data))
      
      httpRequest.send(JSON.stringify(data));
     }
  }
    
  monadsphere.processResponse = function(httpRequest) {
    if (httpRequest.readyState == 4) {
      if (httpRequest.status == 200) {
        eval(httpRequest.responseText);
      } else {
        alert('There is a problem with the request:' + httpRequest.status);
      }
    }
  }

  monadsphere.loadScript = function (scriptName, callback) {
    var path = window.location.pathname;
    callName = path.substring(0, path.lastIndexOf('/') + 1) + scriptName;
    var httpRequest = new XMLHttpRequest();
    httpRequest.onreadystatechange = function() {
      monadsphere.processCallback(httpRequest, callback);
    };
    httpRequest.open('GET', scriptName, true);
    httpRequest.send(null);
  }
    
  monadsphere.processCallback = function(httpRequest, callback) {
    if (httpRequest.readyState == 4) {
      if (httpRequest.status == 200) {
        eval('(function(){' + httpRequest.responseText + '})()' );
        callback("There is a problem: " + httpRequest.status);
      } else {
        alert('There is a problem with the callback:' + httpRequest.status);
      }
    }
  }

</script>
</head>

<body id="root"
      style="margin:0"
      onload="monadsphere.ids.root=document.body;monadsphere.remoteCall('init')">
</body>

</html>
